package wx.event.utils;

import lombok.Data;

import java.util.Arrays;
import java.util.function.Predicate;

/**
 * 消息类型
 */
public enum MessageUtil {
    返回消息类型_文本("text", 1),
    返回消息类型_音乐("music", 2),
    返回消息类型_图文("news", 3),
    返回消息类型_多客服("transfer_customer_service", 4),
    请求消息类型_文本("text", 5),
    请求消息类型_图片("image", 6),
    请求消息类型_语音("voice", 7),
    请求消息类型_视频("video", 8),
    请求消息类型_小视频("shortvideo", 9),
    请求消息类型_地理位置("location", 10),
    请求消息类型_链接消息("link", 11),
    请求消息类型_推送("event", 12),
    事件类型_关注("subscribe", 13),
    事件类型_取消关注("unsubscribe", 14),
    事件类型_扫描("SCAN", 15),
    事件类型_扫描2("scancode_waitmsg", 16),
    事件类型_扫描3("scancode_push", 17),
    事件类型_CLICK点击菜单("CLICK", 18),
    事件类型_VIEW点击菜单("VIEW", 19);
    private String type;
    private int index;
    private MessageUtil(String _type, int _index){
        this.type = _type;
        this.index = _index;
    }
    public static String getType(int _index){
        //定义filter
        Predicate<MessageUtil> indexFilter = (item) -> (item.getIndex() == _index);
        //遍历
        MessageUtil t = Arrays.asList(MessageUtil.values())
                .stream()
                .filter(indexFilter)
                .findFirst().orElse(null);
        return t == null ? null : t.getType();
    }
    public String getType() {
        return type;
    }
    public void setType(String type) {
        this.type = type;
    }
    public int getIndex() {
        return index;
    }
    public void setIndex(int index) {
        this.index = index;
    }
}
